<?php
namespace app\admin\middleware;
use think\facade\Db;
class SaveLog
{
    public function handle($request, \Closure $next)
    {
        // 在请求处理之前做一些事情
        $this->save_log($request);

        // 处理请求
        $response = $next($request);

        // 在请求处理之后做一些事情
        // 这里可以根据你的需求来记录响应日志或其他信息

        return $response;
    }
    function save_log($request) {
        $post = input('post.');
        $get = input('get.');
        if($post || $get){
            $pathinfo = $request->pathinfo();
            $pathinfo = pathinfo($pathinfo);
            $controller = $pathinfo['dirname']??'';
            $action = $pathinfo['filename']??"";
            $content = Db::name('system_menu')->where('right',$controller.'@'.$action)->value('name');
            $data = [];
            $data['content']		= $content;//获取权限里面的操作名称
            $data['application']	= app('http')->getName();
            $data['module']			= $controller;
            $data['action']			= $action;
            $data['admin_id']		= session('admin_id')??0;
            $data['admin_name']		= session('admin_name')??'';
            $data['supplier_id']		= session('supplier_id')??0;
            $data['post_data']		= $post?json_encode($post):'';
            $data['get_data']		= $get?json_encode($get):'';
            $data['ip']				= request()->ip();
            $data['create_time']	= time();
            Db::name('sys_log')->insert($data);
        }
    }
}